﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace RhythmComet.Utils
{
    public class AlertMessage
    {
        private float durationTime;
        private float elapsedTime;
        bool toggleMessage;

        public AlertMessage(float durationTime)
        {
            this.durationTime = durationTime;
            this.elapsedTime = 0.0f;
            this.toggleMessage = false;
        }


        public void Draw(String message, Vector2 position, GameTime gameTime, SpriteBatch spriteBatch, SpriteFont font)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
            elapsedTime += dt;

            if (toggleMessage)
            {
                spriteBatch.Begin();
                spriteBatch.DrawString(font, message, position, Color.Red);
                spriteBatch.End();
            }

            if (elapsedTime > durationTime)
            {
                elapsedTime = 0.0f;
                toggleMessage = !toggleMessage;
            }
        }

        public void Draw(String message, GameTime gameTime, SpriteBatch spriteBatch, SpriteFont font)
        {
            Vector2 fontOrign = font.MeasureString(message)/2;
            Vector2 position = new Vector2(spriteBatch.GraphicsDevice.Viewport.Width / 2, spriteBatch.GraphicsDevice.Viewport.Height / 2);

            Draw(message, position - fontOrign, gameTime, spriteBatch, font);
        }
    }
}
